<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->unsignedBigInteger('id')->primary();
            $table->unsignedBigInteger('member_id')->default(0)->comment('用户ID')->index('member');
            $table->unsignedBigInteger('refund_user_id')->default(0)->comment('退款处理人')->index('refund_user');
            $table->unsignedBigInteger('device_group_id')->default(0)->comment('设备分组ID')->index('device_group');
            $table->unsignedBigInteger('device_id')->default(0)->comment('设备ID')->index('device');
            $table->enum('device_style',['TEA_HOUSE','INTERNET_CAFE'])->default('INTERNET_CAFE')->comment('款式 TEA_HOUSE茶楼 INTERNET_CAFE网吧');
            $table->unsignedInteger('time_length')->default(0)->comment('时长(分)');
            $table->unsignedBigInteger('marketing_policy_id')->default(0)->comment('使用的营销策略');
            $table->unsignedBigInteger('marketing_policy_rule_id')->default(0)->comment('使用的营销策略规则');
            $table->unsignedBigInteger('price_specification_id')->default(0)->comment('使用的价格策略');
            $table->string('price_specification_name')->default('')->comment('价格档次名称');
            $table->unsignedInteger('price')->default(0)->comment('价格(分)');
            $table->unsignedInteger('paid_price')->default(0)->comment('实付价格(分)');
            $table->string('business_name')->default('')->comment('商户名称');
            $table->enum('channel',['WECHAT','ALIPAY','CASH'])->nullable()->comment('WECHATL微信支付ALIPAY支付宝CASH现金')->index('channel');
            $table->enum('status',['WAIT_PAY','PAY_SUCCESS','USING','WAIT_REFUND','REFUSE_REFUND','REFUND_ING','COMPLETE','REFUND_COMPLETE'])->nullable()->comment('WAIT_PAY等待付款PAY_SUCCESS支付成功USING使用中WAIT_REFUND等待退款REFUSE_REFUND拒绝退款REFUND_ING退款中COMLETE完成REFUND_COMLETE退款完成')->index('status');
            $table->enum('dividend',['NO','YES'])->default('NO')->comment('是否已经分成');
            $table->dateTime('using_time')->nullable()->comment('开始使用的时间');
            $table->dateTime('complete_time')->nullable()->comment('订单完成的时间');
            $table->dateTime('pay_time')->nullable()->comment('付款的时间');
            $table->dateTime('refund_request_time')->nullable()->comment('退款申请时间');
            $table->dateTime('refund_review_time')->nullable()->comment('退款审核时间');
            $table->dateTime('refund_complete_time')->nullable()->comment('退款完成时间');
            $table->string('platform_open_id',64)->nullable()->default('')->comment('平台openid')->index('platform_open_id');
            $table->string('platform_order_no',64)->nullable()->default('')->comment('平台订单号')->index('platform_order_no');
            $table->timestamps();
            $table->softDeletes();
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';
            $table->engine = 'InnoDB';
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }
}
